<template>
    <div class="wrapper">
      <h3>校 友 活 动</h3>
      <el-divider></el-divider>
      <div class="content">
        <ul>
          <li v-for="(item,index) in activityList" :key="index">
            <div style="padding: 5px">
              <img class="itemImg" :src="baseUrl+item.imgList[0].acImgUrl"/>
            </div>
            <div class="context">
              <div class="title"><a :href="'/#/activityDetails?activityId='+item.activityId">{{item.activityName}}</a></div>
              <div class="time"><i class="el-icon-time"></i> {{item.activityTime}} &emsp;<i class="el-icon-view"></i> {{item.views}}</div>
              <div class="detail">
                {{item.activityDetails}}
              </div>
              <el-divider></el-divider>
            </div>
          </li>
        </ul>
        <div style="display: flex; justify-content: flex-end; margin-bottom: 20px">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="current"
            :page-sizes="sizes"
            :page-size="size"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </div>
</template>

<script>
    export default {
        name: "Activity",
        data(){
            return{
                activityList:[],
                current: 1,
                size: 5,
                total: 0,
                sizes: [5,10,15,20],
                baseUrl: 'http://localhost:8888'
            }
        },
        methods:{
            getData(current, size){
                const params={current: current, size: size};
                this.getRequest('/getActivityList', params).then(res=>{
                    if(res){
                        const re=new RegExp('<.+?>','g');
                        res.list.forEach(item=>{
                            item.activityDetails=item.activityDetails.replace(re,'');
                        });
                        this.activityList=res.list;
                        this.total=res.total;
                    }else{
                        this.$message.error('获取活动信息失败！');
                    }
                })
            },
            handleCurrentChange(val){
                this.getData(val, this.size);
            },
            handleSizeChange(val){
                this.getData(this.current, val);
            },
        },
        mounted() {
            this.getData(1,5);
        }
    }
</script>

<style scoped>
  .wrapper{
    padding-left: 5%;
  }
  h3{
    padding-left: 1%;
  }
  .content{
    margin-top: 10px;
  }
  .itemImg{
    width: 200px;
    height: auto;
  }
  li{
    display: flex;
    flex-direction: row;
  }
  .context{
    padding: 5px 0;
  }
  .title{
    font-size: 18px;
    font-weight: bold;
    width: 99%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .title a{
    text-decoration: none;
    color: darkred;
  }
  .title a:hover{
    color: red;
    cursor: pointer;
  }
  .time{
    font-size: 15px;
    color: darkgreen;
    margin: 10px 0;
  }
  .detail{
    font-size: 16px;
    font-family: Arial;
    width: 99%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 2em;
  }
</style>
